package com.testjpa.web;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;

/**
 * 作者: LCG
 * 日期: 2020/5/19 16:26
 * 描述:
 */

@RestController
public class RibbonHyController {

    @Autowired
    private RestTemplate restTemplate;

    @RequestMapping("test04/{id}")
    @HystrixCommand(fallbackMethod = "test05")
    public String test04(@PathVariable("id") String id){

        Map<String,Object> map=new HashMap<>();
        map.put("ok","--------------");
        map.put("id",id);
        String result = restTemplate.postForObject("http://consule-client2/test02", map, String.class);

        return result;
    }


    public String test05(@PathVariable("id") String id){
        System.out.println("==========出错了==="+id);

        return "出错了";
    }

}
